package com.yipinhouse.backstage.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.yipinhouse.backstage.client.EstateWebManageClient;
import com.yipinhouse.backstage.client.param.InsertEstateWebParam;
import com.yipinhouse.backstage.client.param.UpdateEstateWebParam;
import com.yipinhouse.common.result.Result;
import com.yipinhouse.house.client.EstateManageClient;
import com.yipinhouse.house.client.param.InsertEstateParam;
import com.yipinhouse.house.client.param.UpdateEstateParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("backstage")
public class EstateWebManageApiImpl implements EstateWebManageClient {

    @Resource
    private EstateManageClient estateManageClient;
    /**
     * 添加小区
     * @param insertEstateParam
     * @return
     */
    @Override
    public Result insertEstate(InsertEstateWebParam insertEstateParam) {
        log.info("添加小区：{}", insertEstateParam);
        InsertEstateParam insertEstateParams = BeanUtil.copyProperties(insertEstateParam, InsertEstateParam.class);
        estateManageClient.insertEstate(insertEstateParams);
        return Result.getInstance().setMsg("添加成功").setCode(200);
    }

    /**
     * 上传图片
     * @param file
     * @return
     * @throws Exception
     */
    @Override
    public Result uploadImage(MultipartFile file) throws Exception {
        Result result = estateManageClient.uploadImage(file);
        return Result.getInstance(String.class).setData(result.getData().toString());
    }

    /**
     * 修改小区
     * @param param
     * @return
     */
    @Override
    public Result updateEstate(UpdateEstateWebParam param) {
        log.info("修改小区：{}",param);
        UpdateEstateParam updateEstateParam = BeanUtil.copyProperties(param, UpdateEstateParam.class);
        estateManageClient.updateEstate(updateEstateParam);
        return Result.getInstance().setMsg("修改成功").setCode(200);
    }

    /**
     * 删除小区
     * @param estateId
     * @return
     */
    @Override
    public Result deleteEstate(Integer estateId) {
        log.info("删除小区Id：{}",estateId);
        estateManageClient.deleteEstate(estateId);
        return Result.getInstance().setMsg("删除成功").setCode(200);
    }
}
